package com.miyake.dsp.osa;

public class NoiseFigure {
	private final static double C = 2.99792458* 1e8;
	private final static  double h = 6.626e-34;
	
	public static double toFrequency(double wavelength) {
		return C / (wavelength * 1e-9);
	}
	
	public static double calcNFTotal(double ase, double gain, double wavelength, 
			double rbw, double k, double tpin, double bpfbw) {	
		double x = getX(ase, gain, wavelength, rbw);
		double dva = C * (1.0/(wavelength*1e-9 - bpfbw*1e-9/2.0) - 1.0/(wavelength*1e-9 + bpfbw*1e9/2.0));
		double v = toFrequency(wavelength);
		double N = tpin / (h * v);
		
		dva = 0; // Ignore this. Filter 
		return k * (x + Math.pow(x, 2.0)*dva/(2.0*N) + 
				1.0/gain + x*dva/(gain * N));
	}
	
	public static double calcNF(double ase, double gain, double wavelength, double rbw, double k) {
		return k * getX(ase, gain, wavelength, rbw);
	}

	public static double getX(double ase, double gain, double wavelength, double rbw) {
		double v = toFrequency(wavelength);
		double dvs = 
				C / (wavelength * 1e-9 - rbw * 1e-9 / 2.0) -
				C / (wavelength * 1e-9 + rbw * 1e-9 / 2.0);
		//return k1 * ase / (h * v * gain * dvs);
		return ase / h / v / gain / dvs;
	}
	
	public static double calcNFYokogawa(double ase, double gain, double wavelength, double rbw) {
//		double RRBW = 0.03; // nm
		return Math.pow(wavelength*1e-9, 3.0) * ase / (h * Math.pow(C, 2.0) * rbw * 1e-9 * gain);
	}
}
